package view;

import javax.swing.JPanel;
import javax.swing.JFrame;
import java.awt.Dimension;
import javax.swing.JTabbedPane;
import java.awt.Rectangle;
import java.awt.Color;
import javax.swing.BorderFactory;
import java.awt.Point;

import javax.swing.ButtonGroup;
import javax.swing.JMenuBar;
import javax.swing.JMenu;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;

import java.awt.Font;
import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.ArrayList;

import javax.swing.border.TitledBorder;
import javax.swing.JRadioButton;
import javax.swing.JPasswordField;

import model.roleModel;
import model.userModel;

import com.toedter.calendar.JDateChooser;
import common.loadData;

import dao.encrypt;
import dao.menuDao;
import dao.userdao;
import javax.swing.SwingConstants;
import javax.swing.JMenuItem;

public class mainForm extends JFrame {

	private static final long serialVersionUID = 1L;
	private JPanel jContentPane = null;
	private JMenuBar jJMenuBar = null;
	private JMenu jMenu = null;
	private JMenu jMenu_help = null;
	private JLabel jLabel_logo = null;
	private JLabel jLabel_user = null;
	private JLabel jLabel_name = null;
	private JLabel jLabel_function = null;
	private JLabel jLabel_search = null;
	private JTextField txtsearch = null;
	private JLabel jLabel_choose = null;
	private JComboBox ComboBoxChoose = null;
	private JButton ButtonSearch = null;
	private JTabbedPane TabbedPane = null;
	private JPanel jPanel = null;
	private JPanel panelTitle = null;
	private JLabel LabeleditInfo = null;
	private JPanel PanelAcount = null;
	private JLabel LabelUserName = null;
	private JLabel LabelPass = null;
	private JTextField txtUsername = null;
	private JLabel LabelStatus = null;
	private JLabel LabelRole = null;
	private JComboBox ComboBoxRole = null;
	private JRadioButton RadioButtonlock = null;
	private JRadioButton RadioButtonUnlock = null;
	private JPanel PanelInfomation = null;
	private JLabel LabelFname = null;
	private JLabel LabelLname = null;
	private JLabel LabelSex = null;
	private JPasswordField txtPass = null;
	private JTextField txtFname = null;
	private JTextField txtLname = null;
	private JRadioButton RadioButtonMale = null;
	private JRadioButton RadioButtonFemale = null;
	private ButtonGroup goupsex=null; 
	private ButtonGroup gouplock=null; 
	private JLabel LabelDate = null;
	private JDateChooser txtDate = null;
	private JLabel LabelAddress = null;
	private JTextField txtAddress = null;
	private JButton ButtonEdit = null;
	private JButton ButtonSave = null;
	private String [] permiss=null;
	public static int id;
	public static String search;
	private JMenuItem MenuItemLogout = null;
	public mainForm() {
		super();
		try {
			getPhanQuyen();
			initialize();
			loadpersonal();
			permiss();
			enableFalse(false);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private void enableFalse(boolean a)
	{
		txtAddress.setEnabled(a);
		txtDate.setEnabled(a);
		txtFname.setEnabled(a);
		txtLname.setEnabled(a);
		txtPass.setEnabled(a);
		txtUsername.setEnabled(a);
		RadioButtonFemale.setEnabled(a);
		RadioButtonlock.setEnabled(a);
		RadioButtonMale.setEnabled(a);
		RadioButtonUnlock.setEnabled(a);
		ComboBoxRole.setEnabled(a);
		ButtonSave.setEnabled(a);
	}
	private void permiss()
	{
		jLabel_name.setText("Name:"+" "+txtFname.getText()+" "+txtLname.getText());
		jLabel_user.setText("UserName:"+" "+txtUsername.getText());
		if(login.idrole==0)
		{
			jLabel_function.setText("Admin Management");
		}
		else
		jLabel_function.setText("User Management");
	}
	private void initialize() {
		this.setResizable(false);
		this.setBounds(new Rectangle(200, 5, 900, 700));
		this.setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/image/management.png")));
		this.setName("MainForm");
		this.setJMenuBar(getJJMenuBar());
		this.setBackground(new Color(0, 153, 153));
		this.setContentPane(getJContentPane());
		this.setTitle("Crimefile System");
	}

	private JPanel getJContentPane() {
		if (jContentPane == null) {
			jLabel_choose = new JLabel();
			jLabel_choose.setForeground(Color.white);
			jLabel_choose.setSize(new Dimension(49, 23));
			jLabel_choose.setLocation(new Point(671, 81));
			jLabel_choose.setText("Choose");
			jLabel_search = new JLabel();
			jLabel_search.setForeground(Color.white);
			jLabel_search.setSize(new Dimension(51, 24));
			jLabel_search.setLocation(new Point(477, 81));
			jLabel_search.setText("Search");
			jLabel_function = new JLabel();
			jLabel_function.setBounds(new Rectangle(306, 18, 400, 34));
			jLabel_function.setFont(new Font("MS PGothic", Font.BOLD | Font.ITALIC, 36));
			jLabel_function.setForeground(Color.white);
			jLabel_function.setText("User");
			jLabel_name = new JLabel();
			jLabel_name.setBounds(new Rectangle(119, 66, 150, 24));
			jLabel_name.setForeground(Color.white);
			jLabel_name.setText("Name:");
			jLabel_user = new JLabel();
			jLabel_user.setBounds(new Rectangle(121, 22, 150, 27));
			jLabel_user.setForeground(Color.white);
			jLabel_user.setText("Username:");
			jLabel_logo = new JLabel();
			jLabel_logo.setBounds(new Rectangle(16, 1, 75, 96));
			jLabel_logo.setIcon(new ImageIcon(getClass().getResource("/image/logo.png")));
			jLabel_logo.setText("");
			jContentPane = new JPanel();
			jContentPane.setLayout(null);
			jContentPane.setBackground(new Color(11, 94, 94));
			jContentPane.setBorder(BorderFactory.createLineBorder(Color.white, 0));
			jContentPane.add(jLabel_logo, null);
			jContentPane.add(jLabel_user, null);
			jContentPane.add(jLabel_name, null);
			jContentPane.add(jLabel_function, null);
			jContentPane.add(jLabel_search, null);
			jContentPane.add(getTxtsearch(), null);
			jContentPane.add(jLabel_choose, null);
			jContentPane.add(getComboBoxChoose(), null);
			jContentPane.add(getButtonSearch(), null);
			jContentPane.add(getTabbedPane(), null);
		}
		return jContentPane;
	}

	private JMenuBar getJJMenuBar() {
		if (jJMenuBar == null) {
			jJMenuBar = new JMenuBar();
			jJMenuBar.setPreferredSize(new Dimension(0, 20));
			jJMenuBar.add(getJMenu());
			jJMenuBar.add(getJMenu_help());
		}
		return jJMenuBar;
	}

	private JMenu getJMenu() {
		if (jMenu == null) {
			jMenu = new JMenu();
			jMenu.setText("System");
			jMenu.add(getMenuItemLogout());
		}
		return jMenu;
	}

	private JMenu getJMenu_help() {
		if (jMenu_help == null) {
			jMenu_help = new JMenu();
			jMenu_help.setText("Help");
		}
		return jMenu_help;
	}

	private JTextField getTxtsearch() {
		if (txtsearch == null) {
			txtsearch = new JTextField();
			txtsearch.setSize(new Dimension(120, 24));
			txtsearch.setLocation(new Point(537, 81));
		}
		return txtsearch;
	}

	private JComboBox getComboBoxChoose() {
		if (ComboBoxChoose == null) {
			ComboBoxChoose = new JComboBox();
			ComboBoxChoose.setLocation(new Point(724, 80));
			ComboBoxChoose.setSize(new Dimension(106, 24));
			ComboBoxChoose.addItem("Select topic");
			ComboBoxChoose.addItem("Criminal");
			ComboBoxChoose.addItem("Prisoner");
			ComboBoxChoose.addItem("Postmortem");
			ComboBoxChoose.addItem("Most Wanted");
			ComboBoxChoose.addItem("Complaint");
			ComboBoxChoose.addItem("FIR");
			ComboBoxChoose.addItem("History");
			if(login.idrole==0)
			{
				ComboBoxChoose.addItem("User");
			}
			ComboBoxChoose.setSelectedIndex(0);
			
			
		}
		return ComboBoxChoose;
	}

	private JButton getButtonSearch() {
		if (ButtonSearch == null) {
			ButtonSearch = new JButton();
			ButtonSearch.setIcon(new ImageIcon(getClass().getResource("/image/Search.gif")));
			ButtonSearch.setLocation(new Point(844, 81));
			ButtonSearch.setSize(new Dimension(25, 22));
			ButtonSearch.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					search=txtsearch.getText();
					if(ComboBoxChoose.getSelectedIndex()==5)
					{
						loadData.loadDatassearchComplaint();
						loadData.tab=5;
					}else if(ComboBoxChoose.getSelectedIndex()==1)
					{
						loadData.datacriminalSearch();
						loadData.tab=2;
					}else if(ComboBoxChoose.getSelectedIndex()==2)
					{
						loadData.datasearchprisoner();
						loadData.tab=3;
					}else if(ComboBoxChoose.getSelectedIndex()==4)
					{
						loadData.datamostwanted();
						loadData.tab=7;
					}else if(ComboBoxChoose.getSelectedIndex()==3)
					{
						loadData.loadDatasearchPostmortem();
						loadData.tab=4;
					}else if(ComboBoxChoose.getSelectedIndex()==8)
					{
						loadData.loadDataSearchUser();
						loadData.tab=1;
					}else if(ComboBoxChoose.getSelectedIndex()==6)
					{
						loadData.dataSearchFir();
						loadData.tab=6;
					}else if(ComboBoxChoose.getSelectedIndex()==7)
					{
						loadData.loadDataSearchHis();
						loadData.tab=8;
					}else
					{
						JOptionPane.showMessageDialog(null, "Choice topic you want to search!");
					}
					
					(new mainForm()).setVisible(true);
					dispose();
				}
			});
		}
		return ButtonSearch;
	}	
	private void getPhanQuyen(){
		ArrayList<roleModel> listrole = menuDao.getAllRoleMenuByID(login.idrole);
		permiss = new String[listrole.size()];
		int i=0;
		for (roleModel model : listrole) {
			permiss[i] = model.getIdMenu();
			i++;
		}
	}

	private JTabbedPane getTabbedPane() {
		if (TabbedPane == null) {
			 panelmanageuser user = new panelmanageuser(this);
			 panelCriminal criminal = new panelCriminal(this);
			 panelPrisoner prisoner = new panelPrisoner(this);
			 panelPostmortem postmortem = new panelPostmortem(this);
			 panelComplaint complaints = new panelComplaint(this);
			 panelFIR fir = new panelFIR(this);
			 panelHistiry his = new panelHistiry(this);
			 panelMostWanted mostWanted = new panelMostWanted(this);
			TabbedPane = new JTabbedPane();
			TabbedPane.setSize(new Dimension(882, 531));
			TabbedPane.setLocation(new Point(0, 110));
			TabbedPane.setTabPlacement(JTabbedPane.LEFT);
			TabbedPane.addTab("Personal", new ImageIcon(getClass().getResource("/image/personal.png")), getJPanel(), null);			
			for (int i=0; i<permiss.length;i++) {
				if(permiss[i].endsWith("2"))
				TabbedPane.addTab("Manage User", new ImageIcon(getClass().getResource("/image/group.png")), user, null);
				else if(permiss[i].endsWith("3"))
				TabbedPane.addTab("Criminal", new ImageIcon(getClass().getResource("/image/crim.png")), criminal, null);
				else if(permiss[i].endsWith("4"))
				TabbedPane.addTab("Prisoner", new ImageIcon(getClass().getResource("/image/prisoner.png")), prisoner, null);
				else if(permiss[i].endsWith("5"))
				TabbedPane.addTab("postmortem", new ImageIcon(getClass().getResource("/image/postmor.png")), postmortem, null);
				else if(permiss[i].endsWith("6"))
				TabbedPane.addTab("Complaint", new ImageIcon(getClass().getResource("/image/complaint.png")), complaints, null);
				else if(permiss[i].endsWith("7"))
				TabbedPane.addTab("FIR Manage", new ImageIcon(getClass().getResource("/image/file.png")), fir, null);
				else if(permiss[i].endsWith("8"))
				TabbedPane.addTab("Most Wanted", new ImageIcon(getClass().getResource("/image/mostwanted.png")), mostWanted, null);
				else if(permiss[i].endsWith("9"))
				TabbedPane.addTab("History", new ImageIcon(getClass().getResource("/image/complaint.png")), his, null);
			}
			TabbedPane.setSelectedIndex(loadData.tab);
		}
		return TabbedPane;
	}

	private JPanel getJPanel() {
		if (jPanel == null) {
			jPanel = new JPanel();
			jPanel.setLayout(null);
			jPanel.add(getPanelTitle(), null);
			jPanel.add(getPanelAcount(), null);
			jPanel.add(getPanelInfomation(), null);
			jPanel.add(getButtonEdit(), null);
			jPanel.add(getButtonSave(), null);
		}
		return jPanel;
	}

	private JPanel getPanelTitle() {
		if (panelTitle == null) {
			LabeleditInfo = new JLabel();
			LabeleditInfo.setBounds(new Rectangle(2, -1, 189, 29));
			LabeleditInfo.setFont(new Font("Dialog", Font.BOLD, 24));
			LabeleditInfo.setForeground(new Color(0, 102, 102));
			LabeleditInfo.setText("Edit Infomation ");
			panelTitle = new JPanel();
			panelTitle.setLayout(null);
			panelTitle.setBounds(new Rectangle(256, 16, 185, 31));
			panelTitle.setBorder(BorderFactory.createTitledBorder(BorderFactory.createMatteBorder(0, 0, 2, 0, Color.red), "", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(51, 51, 51)));
			panelTitle.add(LabeleditInfo, null);
		}
		return panelTitle;
	}

	private JPanel getPanelAcount() {
		if (PanelAcount == null) {
			LabelRole = new JLabel();
			LabelRole.setText("Role:");
			LabelRole.setLocation(new Point(329, 90));
			LabelRole.setSize(new Dimension(77, 28));
			LabelStatus = new JLabel();
			LabelStatus.setText("Status:");
			LabelStatus.setLocation(new Point(330, 35));
			LabelStatus.setSize(new Dimension(76, 29));
			LabelPass = new JLabel();
			LabelPass.setText("Password:");
			LabelPass.setLocation(new Point(50, 90));
			LabelPass.setSize(new Dimension(77, 37));
			LabelUserName = new JLabel();
			LabelUserName.setText("Username:");
			LabelUserName.setLocation(new Point(50, 35));
			LabelUserName.setSize(new Dimension(74, 34));
			PanelAcount = new JPanel();
			PanelAcount.setLayout(null);
			PanelAcount.setBounds(new Rectangle(46, 59, 655, 153));
			PanelAcount.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(0, 0, 153), 1), "Account", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(0, 0, 153)));
			PanelAcount.setEnabled(false);
			PanelAcount.add(LabelUserName, null);
			PanelAcount.add(LabelPass, null);
			PanelAcount.add(getTxtUsername(), null);
			PanelAcount.add(LabelStatus, null);
			PanelAcount.add(LabelRole, null);
			PanelAcount.add(getComboBoxRole(), null);
			PanelAcount.add(getRadioButtonlock(), null);
			PanelAcount.add(getRadioButtonUnlock(), null);
			gouplock = new ButtonGroup();
			gouplock.add(getRadioButtonlock());
			gouplock.add(getRadioButtonUnlock());
			PanelAcount.add(getTxtPass(), null);
			PanelAcount.setEnabled(false);
		}
		return PanelAcount;
	}

	private JTextField getTxtUsername() {
		if (txtUsername == null) {
			txtUsername = new JTextField();
			txtUsername.setSize(new Dimension(150, 29));
			txtUsername.setLocation(new Point(135, 35));
		}
		return txtUsername;
	}

	private JComboBox getComboBoxRole() {
		if (ComboBoxRole == null) {
			ComboBoxRole = new JComboBox();
			ComboBoxRole.setLocation(new Point(421, 90));
			ComboBoxRole.setSize(new Dimension(150, 29));
			ComboBoxRole.addItem("Admin");
			ComboBoxRole.addItem("User");
			ComboBoxRole.setSelectedIndex(0);
			if(login.idrole==1)
			{
				ComboBoxRole.setEnabled(false);
			}
		}
		return ComboBoxRole;
	}

	private JRadioButton getRadioButtonlock() {
		if (RadioButtonlock == null) {
			RadioButtonlock = new JRadioButton();
			RadioButtonlock.setText("Lock");
			RadioButtonlock.setLocation(new Point(421, 35));
			RadioButtonlock.setSize(new Dimension(74, 27));
		}
		return RadioButtonlock;
	}

	private JRadioButton getRadioButtonUnlock() {
		if (RadioButtonUnlock == null) {
			RadioButtonUnlock = new JRadioButton();
			RadioButtonUnlock.setText("Unlock");
			RadioButtonUnlock.setLocation(new Point(495, 35));
			RadioButtonUnlock.setSize(new Dimension(76, 29));
		}
		return RadioButtonUnlock;
	}

	private JPanel getPanelInfomation() {
		if (PanelInfomation == null) {
			LabelAddress = new JLabel();
			LabelAddress.setBounds(new Rectangle(330, 90, 76, 30));
			LabelAddress.setText("Address:");
			LabelDate = new JLabel();
			LabelDate.setText("Birth of Date:");
			LabelDate.setLocation(new Point(330, 35));
			LabelDate.setSize(new Dimension(80, 27));
			LabelSex = new JLabel();
			LabelSex.setBounds(new Rectangle(48, 151, 74, 31));
			LabelSex.setText("Sex:");
			LabelLname = new JLabel();
			LabelLname.setBounds(new Rectangle(50, 89, 73, 31));
			LabelLname.setText("Last Name:");
			LabelFname = new JLabel();
			LabelFname.setText("First Name:");
			LabelFname.setLocation(new Point(50, 35));
			LabelFname.setSize(new Dimension(76, 29));
			PanelInfomation = new JPanel();
			PanelInfomation.setLayout(null);
			PanelInfomation.setSize(new Dimension(655, 214));
			PanelInfomation.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(new Color(0, 0, 153), 1), "Infomation", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION, new Font("Dialog", Font.BOLD, 12), new Color(0, 0, 153)));
			PanelInfomation.setLocation(new Point(46, 243));
			PanelInfomation.add(LabelFname, null);
			PanelInfomation.add(LabelLname, null);
			PanelInfomation.add(LabelSex, null);
			PanelInfomation.add(getTxtFname(), null);
			PanelInfomation.add(getTxtLname(), null);
			PanelInfomation.add(getRadioButtonMale(), null);
			PanelInfomation.add(getRadioButtonFemale(), null);
			goupsex = new ButtonGroup();
			goupsex.add(getRadioButtonMale());
			goupsex.add(getRadioButtonFemale());
			PanelInfomation.add(LabelDate, null);
			PanelInfomation.add(getTxtDate(), null);
			PanelInfomation.add(LabelAddress, null);
			PanelInfomation.add(getTxtAddress(), null);
		}
		return PanelInfomation;
	}

	private JPasswordField getTxtPass() {
		if (txtPass == null) {
			txtPass = new JPasswordField();
			txtPass.setLocation(new Point(136, 89));
			txtPass.setSize(new Dimension(150, 29));
		}
		return txtPass;
	}

	private JTextField getTxtFname() {
		if (txtFname == null) {
			txtFname = new JTextField();
			txtFname.setLocation(new Point(135, 35));
			txtFname.setSize(new Dimension(150, 29));
		}
		return txtFname;
	}

	private JTextField getTxtLname() {
		if (txtLname == null) {
			txtLname = new JTextField();
			txtLname.setLocation(new Point(135, 91));
			txtLname.setSize(new Dimension(150, 29));
		}
		return txtLname;
	}

	private JRadioButton getRadioButtonMale() {
		if (RadioButtonMale == null) {
			RadioButtonMale = new JRadioButton();
			RadioButtonMale.setBounds(new Rectangle(134, 150, 67, 30));
			RadioButtonMale.setText("Male");
		}
		return RadioButtonMale;
	}

	private JRadioButton getRadioButtonFemale() {
		if (RadioButtonFemale == null) {
			RadioButtonFemale = new JRadioButton();
			RadioButtonFemale.setBounds(new Rectangle(202, 150, 83, 31));
			RadioButtonFemale.setText("Female");
		}
		return RadioButtonFemale;
	}

	private JDateChooser getTxtDate() {
		if (txtDate == null) {
			txtDate = new JDateChooser();
			txtDate.setDateFormatString("MM/dd/yyyy");
			txtDate.setSize(new Dimension(150, 29));
			txtDate.setLocation(new Point(422, 36));
			txtDate.getDateEditor().setEnabled(false);
		}
		return txtDate;
	}

	private JTextField getTxtAddress() {
		if (txtAddress == null) {
			txtAddress = new JTextField();
			txtAddress.setLocation(new Point(420, 90));
			txtAddress.setSize(new Dimension(209, 29));
		}
		return txtAddress;
	}

	private JButton getButtonEdit() {
		if (ButtonEdit == null) {
			ButtonEdit = new JButton();
			ButtonEdit.setText("Edit");
			ButtonEdit.setLocation(new Point(425, 481));
			ButtonEdit.setIcon(new ImageIcon(getClass().getResource("/image/Modify.png")));
			ButtonEdit.setHorizontalAlignment(SwingConstants.LEFT);
			ButtonEdit.setHorizontalTextPosition(SwingConstants.RIGHT);
			ButtonEdit.setSize(new Dimension(91, 32));
			ButtonEdit.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					enableFalse(true);
					ButtonEdit.setEnabled(false);
				}
			});
		}
		return ButtonEdit;
	}

	private JButton getButtonSave() {
		if (ButtonSave == null) {
			ButtonSave = new JButton();
			ButtonSave.setText("Save");
			ButtonSave.setSize(new Dimension(91, 32));
			ButtonSave.setIcon(new ImageIcon(getClass().getResource("/image/Save.png")));
			ButtonSave.setHorizontalAlignment(SwingConstants.LEFT);
			ButtonSave.setHorizontalTextPosition(SwingConstants.RIGHT);
			ButtonSave.setLocation(new Point(555, 481));
			ButtonSave.addActionListener(new ActionListener() {
				@Override
				public void actionPerformed(ActionEvent arg0) {
					//chua validate
					userModel model = new userModel();
					model.setId(id);
					model.setIdrole(ComboBoxRole.getSelectedIndex());
					model.setUserName(txtUsername.getText());
					model.setPassWprd(encrypt.maHoaPw(txtPass.getText()));
					model.setFirstName(txtFname.getText());
					model.setLastName(txtLname.getText());
					if(RadioButtonMale.isSelected())
					{
						model.setSex(1);
					}
					else
					{
						model.setSex(0);
					}
					SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
					String da = sdf.format(txtDate.getDate());
					model.setBirth_date(da);
					model.setAddress(txtAddress.getText());
					if(RadioButtonUnlock.isSelected())
					{
						model.setStatus(1);
					}
					else
					{
						model.setStatus(0);
					}
					java.util.Date now = new java.util.Date();
					String d = sdf.format(now);
					model.setLast_update(d);
					// process add User
					int rs = userdao.updateuser(model);
					if(rs==1)
					{
						JOptionPane.showMessageDialog(null, "Update sucessful!");
					}
					else
					{
						JOptionPane.showMessageDialog(null, "Update failed!");
					}
					enableFalse(false);
					ButtonEdit.setEnabled(true);
				}
			});
		}
		return ButtonSave;
	}
	
	private void loadpersonal()
	{
		ArrayList<userModel> personal = userdao.getdatauser(login.IdUser);
		for(userModel model : personal)
		{
			id=model.getId();
			txtUsername.setText(model.getUserName());
			txtPass.setText(model.getPassWprd());
			if(model.getStatus()==1)
			{
				RadioButtonUnlock.setSelected(true);
			}
			else
			{
				RadioButtonlock.setSelected(true);
			}
			txtFname.setText(model.getFirstName());
			txtLname.setText(model.getLastName());
			try{
			SimpleDateFormat sdf = new SimpleDateFormat("mm/dd/yyyy");
			txtDate.setDate(sdf.parse(model.getBirth_date()));
			}catch (Exception e) {
				e.printStackTrace();
			}
			txtAddress.setText(model.getAddress());
			if(model.getSex()==1)
			{
				RadioButtonMale.setSelected(true);
			}
			else
			{
				RadioButtonFemale.setSelected(true);
			}
			if(model.getIdrole()==0)
			{
				ComboBoxRole.setSelectedIndex(0);
			}
			else
			{
			ComboBoxRole.setSelectedIndex(1);
			}
			
		}
		
	}

	private JMenuItem getMenuItemLogout() {
		if (MenuItemLogout == null) {
			MenuItemLogout = new JMenuItem();
			MenuItemLogout.setText("Logout");
			MenuItemLogout.addActionListener(new ActionListener() {
				
				@Override
				public void actionPerformed(ActionEvent arg0) {
					login lg = new login();
					lg.setVisible(true);
					dispose();
				}
			});
		}
		return MenuItemLogout;
	}

} 
